package com.itHaipeng.web.old;

import com.alibaba.fastjson.JSON;
import com.itHaipeng.pojo.Brand;
import com.itHaipeng.service.BrandService;
import com.itHaipeng.service.impl.BrandServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/selectAll")
public class SelectAllServlet extends HttpServlet {
    private BrandService brandService=new BrandServiceImpl();//利用多态
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/json;charset=UTF-8");
        List<Brand> brands = brandService.selectAll();
        String jsonString = JSON.toJSONString(brands);
        if(jsonString!=null){
            response.getWriter().write(jsonString);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
